# $Id: $


package Zuz::Factory;

use strict;
use warnings;

use Dancer ':syntax';
use Readonly;
use Zuz::Action::Welcome;
use Zuz::Action::Login;
use Zuz::Action::Client::Start;
use Zuz::Action::Stuff::Start;
#use Zuz::Utils qw(is_module_name_valid);

Readonly my $DEFAULT_MODULE = 'Zuz::Action::Welcome';

sub create_action {
	my $class   = shift;
	my $package = shift;

	my $action_pm = "Zuz::Action::$package";
	debug "action_pm1 = [$action_pm]";
	debug "WE ARE IN FACTORY!";

	if ( not _is_module_name_valid($action_pm) ){
		$action_pm = $DEFAULT_MODULE;
	}

	return $action_pm->new( @_ );
}

sub _is_module_name_valid {
	my $module = shift;

	return if !$module;
	return if $module !~ /^[\w:]{1,60}$/g;

	$module =~ s/::/\\/g;

	if ( -e "$ENV{'ZUZ'}\\lib\\$module.pm" ) {
		return 1;
	}
	else {
		return 0;
	}
}


1;